package com.hm.hsw1;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Demo {
    public static void main(String[] args) {
        read1();
        System.out.println();
        read2();
    }

    public static void read1() {
        //TODO 一次读取一个字节
        try(FileInputStream fileInputStream=new FileInputStream("D:/file01.txt")){
           while(true){
               int read = fileInputStream.read();
               if(read==-1){
                   break;
               }
               System.out.print((char)read);
           }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void read2() {
        //TODO 一次读取多个字节
        try(FileInputStream fileInputStream=new FileInputStream("D:/file01.txt")){
            byte[] bytes = new byte[3];
            int len;
            while(true){
              len= fileInputStream.read(bytes);
              if(len==-1){
                  break;
              }
                String s = new String(bytes);
                System.out.print(s);

            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

